package com.warrantyhotel.android.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.warrantyhotel.android.R;
import com.warrantyhotel.android.db.WarrantyHotelDBSchema.CountryTable;

public class CountriesAdapter extends CursorAdapter
{

	private LayoutInflater mInflater;

	public CountriesAdapter(Context context, Cursor c)
	{
		super(context, c, false);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor)
	{
		final CountryItem item = (CountryItem) view.getTag();

		item.countryName.setText(cursor.getString(cursor
				.getColumnIndex(CountryTable.NAME)));
		item.countryName.setTag(cursor.getString(cursor
				.getColumnIndex(CountryTable.COUNTRY_ID)));
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent)
	{
		CountryItem item = new CountryItem();
		View view = mInflater.inflate(R.layout.spinner_country_item, null);
		item.countryName = (TextView) view.findViewById(R.id.country_name);
		view.setTag(item);
		return view;
	}

	public static class CountryItem
	{
		public TextView countryName;
	}

}
